/*
 * 创建日期 2006-10-7
 *
 * 更改所生成文件模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
package com.vanda.report.view;

import java.math.BigDecimal;

import org.apache.poi.hssf.usermodel.HSSFCell;

import com.vanda.report.ExcelUtils;
import com.vanda.report.ReportException;
import com.vanda.report.ReportInnerData;
import com.vanda.report.Validation;
import com.vanda.report.element.Element;

/**
 * @author wangying
 *
 * 更改所生成类型注释的模板为
 * 窗口 > 首选项 > Java > 代码生成 > 代码和注释
 */
public class FormulaElement extends Element {
	
	private String cell_id = null;
	
	public void validator() throws ReportException{
		Validation.checkRequired("FormulaElement","cell_id",cell_id);
	}
	
	/**
	 * 标签执行方法，递归执行
	 * temp1:保存公式执行结果
	 * @param obj
	 */
	public void execute(Object obj) throws ReportException{
		ReportInnerData reportData = (ReportInnerData)obj;
		try{
			//清空temp1
			reportData.setTemp1(new BigDecimal("0"));

			super.execute(obj);
			
			Object result = reportData.getTemp1();
			if(result != null){
				//取得需要计算公式的cell
				HSSFCell cell = ExcelUtils.getCell(reportData.getReportSheet(),cell_id);
				//将结果设置到cell
				ExcelUtils.setCellValue(cell,result,"number");
			}
			
			//System.out.println("copy currentRow = "+reportData.getCurrentRow());
		}catch(ReportException e){
			throw e;
		}catch(Exception e){
			throw new ReportException(e);
		}
	}




	/**
	 * @return
	 */
	public String getCell_id() {
		return cell_id;
	}

	/**
	 * @param string
	 */
	public void setCell_id(String string) {
		cell_id = string;
	}

}
